package com.hnue.k60b.newapplication;

import com.hnue.k60b.utils.Variables;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class NewActivity extends Activity{

	private WebView webview;
	private String link;
	private ProgressDialog dialog;
	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.article);
		Bundle bundle = getIntent().getExtras();
		setTitle(R.string.app_name);
		link = bundle.getString(Variables.LINK);
		webview = (WebView)findViewById(R.id.webView1);
		webview.getSettings().setSupportZoom(true);
		webview.setInitialScale(1);
		webview.getSettings().setLoadWithOverviewMode(true);
		webview.getSettings().setUseWideViewPort(true);
		//webview.getSettings().setJavaScriptEnabled(true);
		webview.setScrollBarStyle(webview.SCROLLBARS_INSIDE_OVERLAY);
		webview.setScrollbarFadingEnabled(false);
		webview.setWebViewClient(new WebviewCliens());
		dialog = ProgressDialog.show(this, "", "Đang tải ...");
		new NewTask().execute();
		
	}
	
	class NewTask extends AsyncTask<Void, Void, Void>{

		@Override
		protected Void doInBackground(Void... params) {
			webview.loadUrl(link);
			return null;
		}		
	}
	class WebviewCliens extends WebViewClient{
		@Override
		public void onPageFinished(WebView view, String url) {
			if(dialog!=null){
				dialog.dismiss();
			}
			super.onPageFinished(view, url);
		}
		
	}

}
